<?php

namespace App\Admin\Controllers;

use App\Member;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class UserWithdrawController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('财务统计');
            $content->description('财务统计');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('财务统计');
            $content->description('财务统计');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('财务统计');
            $content->description('财务统计');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Member::class, function (Grid $grid) {
            $grid->nickname('用户昵称');
            $grid->wallet_all_push_money('总提成')->display(function($value){
                return "<a href='' target='_blank'>$value</a>";
            })->sortable();
            $grid->wallet_used_push_money('已提现')->display(function($value){
                return "<a href='".route('withdraw.user',['member_id'=>$this->id])."' target='_blank'>$value</a>";
            })->sortable();
            $grid->wallet_push_money('剩余提现')->sortable();
            $grid->disableActions();
            $grid->disableCreateButton();
            $grid->tools(function($tools){
                $tools->batch(function ($batch) {
                    $batch->disableDelete();
                });
            });



        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Member::class, function (Form $form) {

            $form->display('id', 'ID');

        });
    }
}
